package mirfordevoservice.system.req.impl;

import mirfordevoservice.system.GameCenter.GameDataManager;
import mirfordevoservice.system.req.inter_face.ReqMessage;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/**
 * Created by Heart!
 *
 * @Author ZhangChaoJian
 * @Date ${Date}-12:02
 * Wants More Then Try Hard More!
 */

/**
 * 修改密码请求处理
 */
public class ReqUpdatePassword implements ReqMessage {

    @Override
    public void receive(ObjectInputStream in, Socket socket) {

    }

    @Override
    public void sendMsg(ObjectOutputStream out) {

    }

    @Override
    public void receiveAndSend(ObjectInputStream in, ObjectOutputStream out, Socket socket) {
        int returnMsg;
        try {
            Object msg = in.readObject();
            if (!(msg instanceof String[])) {
                System.err.println("接收数据出错:" + this.getClass().getName());
                return;
            }
            String[] reqMsg = (String[]) msg;
            returnMsg = GameDataManager.getInstance().checkChangUserLoginPassword(reqMsg);
            switch (returnMsg) {
                case 1:
                    out.writeObject("读取玩家信息失败");
                    break;
                case 2:
                    out.writeObject("修改成功，请使用新密码登录");
                    break;
                case 3:
                    out.writeObject("原密码错误");
                    break;
                case 4:
                    out.writeObject("未找到账户信息...");
                    break;
            }
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
